#include <iostream>
#include <vector>
using namespace std;
const int N=15;
bool col[N],st1[N*2],st2[N*2];
int ret=0;
int n;
vector<int> path;
void dfs(int pos)
{
	if(pos>n)
	{
		ret++;
		if(ret<=3)
		{
			for(int x:path) cout<<x<<" ";
			cout<<endl;
			return;
		}
	}
	for(int y=1;y<=n;y++)
	{
		if(col[y]||st1[y-pos+n]||st2[y+pos])continue;
		path.push_back(y);
		col[y]=true;st1[y-pos+n]=true;st2[y+pos]=true;
		dfs(pos+1);
		path.pop_back();
		col[y]=false;st1[y-pos+n]=false;st2[y+pos]=false;
	}
}
int main()
{
	cin>>n;
	dfs(1);
	cout<<ret<<endl;
	return 0;
}
